package com.example.test.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {
    private static final String DATABASE_NAME = "znb.db";
    private static final int DATABASE_VERSION = 1;


    // Columns for user table
    public static final String TABLE_USERS = "user";
    public static String COLUMN_PHONE = "phone";
    public static final String COLUMN_PASSWORD = "password";
    public static final String COLUMN_NAME = "name";
    public static final String COLUMN_CONCERN = "concern";
    public static final String COLUMN_AGE = "age";
    public static final String COLUMN_PAY_PASSWORD = "pay_password";
    public static final String COLUMN_LOCAL = "local";
    private static final String CREATE_TABLE_USERS = "CREATE TABLE "
            + TABLE_USERS + "("
            + COLUMN_PHONE + " TEXT PRIMARY KEY," // Use phone as primary key
            + COLUMN_NAME + " TEXT,"
            + COLUMN_PASSWORD + " TEXT,"
            + COLUMN_CONCERN + " TEXT,"
            + COLUMN_AGE + " TEXT,"
            + COLUMN_PAY_PASSWORD + " TEXT,"
            + COLUMN_LOCAL + " TEXT"
            + ")";



//    //关于账户表的创建
//    public static final String TABLE_NEWS = "news ";
//    public static final String NEWS_ID = " id " ;
//    public static final String NEWS_TYPE = " type " ;
//    public static final String NEWS_TITLE = " first_title " ;
//    public static final String NEWS_SECOND_TITLE = " second_title " ;
//    public static final String NEWS_IMG = " img " ;
//    public static final String NEWS_TEXT = " texts " ;
//    public static final String NEWS_PUBLISHER = "publisher" ;
//
//    private static final String CREATE_TABLE_NEWS = "CREATE TABLE " + TABLE_NEWS +
//            "(" + NEWS_ID + "INTEGER PRIMARY KEY AUTOINCREMENT ," +
//            NEWS_TYPE + "TEXT NOT NULL," +
//            NEWS_TITLE + "TEXT ," +
//            NEWS_SECOND_TITLE + "TEXT ," +
//            NEWS_IMG + "TEXT ," +
//            NEWS_TEXT + "TEXT ," +
//            NEWS_PUBLISHER + "TEXT )" ;

    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE_USERS);
        //db.execSQL(CREATE_TABLE_NEWS);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERS);
        //db.execSQL("DROP TABLE IF EXISTS " + TABLE_NEWS);
        onCreate(db);
    }
}